package logic

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"group-card/common/tool"
	"group-card/model/entity"
	"group-card/rpc/card/cardclient"
	"group-card/rpc/card/internal/svc"
)

type BindingAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewBindingAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BindingAddLogic {
	return &BindingAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *BindingAddLogic) BindingAdd(in *cardclient.BindingAddRequest) (*cardclient.BindingAddResponse, error) {

	data := entity.CardBindingReq{
		CardNumber:    in.CardNumber,
		CustomerId:    in.CustomerId,
		UserId:        in.UserId,
		BindingTime:   tool.StringToTime(in.BindingTime),
		FaceValue:     in.FaceValue,
		Balance:       in.Balance,
		Status:        in.Status,
		ServiceNumber: in.ServiceNumber,
	}

	var ctx context.Context
	_, err := l.svcCtx.BindingModel.Insert(ctx, &data)

	if err != nil {
		return nil, err
	}

	return &cardclient.BindingAddResponse{}, nil
}
